package design2.template_method.example.networks;

public class Twitter extends  Network {



	public Twitter(String userName, String password) {
			this.userName = userName;
			this.password = password;
	}

	@Override
	boolean login (String userName, String password){
		System.out.println("检查用户参数");
		System.out.println("name:" + this.userName);
		System.out.print("password:");
		for (int i = 0; i < this.password.length(); i++) {
			System.out.print("*");
		}
		simulateNetworkLatency();
		System.out.println("登录Twitter成功！");
		return true;
	}

	@Override
	boolean sendData ( byte[] data){
		boolean messagePosted = true;
		if (messagePosted) {
			System.out.println("消息：" + new String(data) + "已发布在Twitter上");
			return true;
		}
		return false;
	}

	@Override
	void logOut () {
		System.out.println("用户" + userName + "退出成功");
	}

	//模拟工作状态
	private void simulateNetworkLatency () {
		int i = 0;
		System.out.println();
		while (i < 10) {
			System.out.print(".");
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			i++;
		}
	}
}